<?php
namespace app\admin\logic;


//属性页


use app\admin\model\GoodsProp;
use think\facade\Request;

class GoodsPropLogic{
    //prop属性列表留值操作
    public static function  propData(){
        $param=Request::param();
        $data=[
            'keywords'=>isset($param['keywords'])?$param['keywords']:'',
            'pvalue'=>isset($param['pvalue'])?$param['pvalue']:[],
        ];
        return $data;
    }
    //prop属性列表where拼接
    public static function  propWhere(){
        $where=[];
        $whereOr=[];
        $param=Request::param();
        if (isset($param['keywords']) && !empty($param['keywords'])){
            $where[]=['pname','like','%'.$param['keywords'].'%'];
        }
        if (isset($param['pvalue']) && !empty($param['pvalue'])){
           foreach($param['pvalue'] as $v){
               $whereOr[]=['pvalues','find in set',$v];
           }

        }
        return [$where,$whereOr];
    }
        //属性值转中文形式输出
     public static function   propValues($prop)
     {
         $prop_value = GoodsProp::propValue();


         foreach ($prop as &$v) {
             $pvalue = [];
             $v['pvalues'] = explode(",",$v['pvalues']);
             foreach ($v['pvalues'] as $vv) {
                 foreach ($prop_value as $vvv) {
                     if ($vv == $vvv['vid']) {
                         $pvalue[] = $vvv['prop_value'];
                     }
                 }
             }
             $v['pvalues'] = implode(",", $pvalue);
         }

      return $prop;
     }
}